package entity;
import java.awt.Image;
import java.awt.event.KeyEvent;

import java.util.Vector;

import javax.swing.ImageIcon;
import entity.Card.Item;

public class Pecies extends GameMovableObj{

	protected Image icon;
	protected String name;
	protected int self;
	
	private int canvasX = 0;
	private int canvasY=0;
	private int currentX = 40;
	private int currentY = 60;
	private Vector<Item> item = new Vector<Item>();
	private Item itemUsing = null;
	private Vector<EventLog> event = new Vector<EventLog>();
		
	 public Pecies(String imgs,String iconURL,String name,int self, int cropW, int cropH) {
        super(imgs, cropW, cropH);
        this.name = name;
        this.self = self;
        ImageIcon ii = new ImageIcon(this.getClass().getResource(iconURL));
        icon = ii.getImage();
        this.setCanvasSnapshot(0, 0);
        setX(40);
        setY(60);
    }
	
	public void setCanvasSnapshot(int x, int y) {
		canvasX = x;
		canvasY =y;
	}
	public void setCurrentPosition(int x, int y) {
		currentX = x;
		currentY = y;
	}
	public int getCanvasX() {
		return canvasX;
	}
	public int getCanvasY() {
		return canvasY;
	}
	public int getCurrentPositionX() {
		return currentX;
	}
	public int getCurrentPositionY() {
		return currentY;
	}
  
	public void setSelf(int effect){
		this.self +=effect;
	}

    public void keyPressed(KeyEvent e) {

        int key = e.getKeyCode();

        if (key == KeyEvent.VK_SPACE) {
        }

        if (key == KeyEvent.VK_LEFT) {
            setDX(-1);
        }

        if (key == KeyEvent.VK_RIGHT) {
            setDX(1);
        }

        if (key == KeyEvent.VK_UP) {
            setDY(-1);
        }

        if (key == KeyEvent.VK_DOWN) {
            setDY(1);
        }
    }

   

    public void keyReleased(KeyEvent e) {
        int key = e.getKeyCode();

        if (key == KeyEvent.VK_LEFT) {
            setDX(0);
        }

        if (key == KeyEvent.VK_RIGHT) {
            setDX(0);
        }

        if (key == KeyEvent.VK_UP) {
            setDY(0);
        }

        if (key == KeyEvent.VK_DOWN) {
            setDY(0);
        }
    }
    //for player
    public Image getImageIcon(){
    	return this.icon;
    }
    public int getSelf(){
    	return this.self;
    }
    public String getName(){
    	return this.name;
    }
    
    public int getItemNumber(){
    	int count=0;
    	for(int i=0; i<item.size(); i++){
    		if(item.get(i) != null)
    			count++;
    	}
    	return count;
    }
    
    public Item getItemOnHand(int index){
    	return item.get(index);
    }
    
    public Vector<Item> getAllItemsOnHand() {
    	return item;
    }
    public void setItem(Item card){
    	item.add(card);
    }
    
    public Item getItemUsing(){
    	return itemUsing;
    }
    
    public void setItemUsing(Item itemUse){
	    for(int i=0; i<item.size(); i++){
	    		if(item.get(i) == itemUse){
	    			//System.out.println("Before num:"+ item.size());
	    			this.itemUsing = item.get(i);
	    			item.get(i).setX(-10);
	    			item.get(i).setY(-10);
	    			item.remove(i);
	    			//System.out.println("After num:"+ item.size());
	    		}
	    	}

    	//reset
    	if(itemUse == null)
    		this.itemUsing = null;
    }
    public void protectByOther(Item item){
    	this.itemUsing = item;
    }
    public boolean isItemUsing(){
    	if(itemUsing != null)
    		return true;
    	return false;
    }
    
    public void setEventLog(EventLog event){
    	this.event.add(event);
    }
    
    public Vector<EventLog> getEventLog(){
    	return this.event;
    }
    
}
